[//HAI! I CAN HAZ LASSO?

	protect;
	//$public_content += '<p>'+action_params+'</p>';
	//fail(-1, 'Unknown Error');
	/*
	============================================================
	"Catching action_params"
	*/
	Var: 'this_exit' = (Action_Param: 'exit');
	If: $this_exit != '';
			Var: 'exit' = $this_exit;
	Else;
			If: (Variable_Defined: 'exit') == true;
					If: $exit != '';
							Var: 'exit' = $exit;
					Else;
							Var: 'exit' = (Referrer_URL '?and=' lasso_uniqueID '&exit=/');
					/If;
			Else;
					Var: 'exit' = (Referrer_URL '?and=' lasso_uniqueID '&exit=/');
			/If;
			Var: 'exit' = (Referrer_URL '?and=' lasso_uniqueID '&exit=/');
	/If;
	
	
	
	var(
		'submitted_Login_Name' = (Action_Param: 'this'),
		'submitted_Password' = (Action_Param: 'that'),
		'remember' = (Action_Param: 'remember'),
		'pathTo_Redirect' = $exit,
		);
		
		
		
		
	// Does User email exist at all?
	var: 'statement' = 'SELECT 
			CONCAT(u.First_Name, \' \', u.Last_Name) AS name,
			u.Last_Logged_In,
			u.Number_Of_Logins
		FROM Users AS u JOIN Users_Usertypes AS uut ON u.UID = uut.User_UID 
		LEFT JOIN Usertypes AS ut ON uut.Usertype_UID = ut.UID
		WHERE
			u.Login_Name = "'+$submitted_Login_Name+'"
		';
	inline($connection_db, -SQL=$statement);
			//$public_content += '<pre>'+$statement+'</pre>';
			//fail(-1, 'Unknown Error');
			if(found_count != 0);
					// Yes - email address is in the database...
					
					
					
					
					/*
						============================================================
						Have email - check password...
						------------------------------------------------------------
					*/
					var: 'statement' = 'SELECT 
							CONCAT(u.First_Name, \' \', u.Last_Name) AS name,
							u.Last_Logged_In,
							ut.Access_Level, ut.UID AS Usertype_UID, ut.Title AS Usertype_Title,
							u.Number_Of_Logins, u.UID AS User_UID, u.First_Name, u.Last_Name
							
						FROM Users AS u JOIN Users_Usertypes AS uut ON u.UID = uut.User_UID 
						LEFT JOIN Usertypes AS ut ON uut.Usertype_UID = ut.UID
						WHERE
							u.Login_Name = "'+$submitted_Login_Name+'" AND
							u.Password = "'+$submitted_Password+'"
						LIMIT 1'
						;
						
					inline($connection_db, -SQL=$statement);
							if(found_count == 1);
									/*
										============================================================
										Password matched...
										------------------------------------------------------------
									*/
									var('authenticationStatus' = 'Authorized');
									rows;
											var(
												'User_UID'=column('User_UID'),
												'User_Usertype_UID'=column('Usertype_UID'),
												'User_Usertype_Title'=column('Usertype_Title'),
												'spoof_User_Usertype_UID'=column('Usertype_UID'),
												'spoof_AuthenticationStatus'='Authorized',
												'User_First_Name'=column('First_Name'),
												'User_Name_Last'=column('Last_Name'),
												'User_Last_Logged_In'=column('Last_Logged_In'),
												'User_Number_of_Logins_Old'=integer(column('Number_of_Logins')),
												'User_Access_Level' = (Integer: column('Access_Level')),
												);
									/rows;
									
									
									/*
										============================================================
										Authetication information
										------------------------------------------------------------
										Here is the variabes that the authentication system reads.
										
										This is the information that the spoofing system presents to
										the pageprotection routines.
										------------------------------------------------------------
									*/
									var(
										'apparent_AuthenticationStatus' = $authenticationStatus,
										'apparent_User_Access_Level' = $User_Access_Level,
										'User_Usertype_Title' = $User_Usertype_Title,
										'apparent_User_Usertype_UID' = $User_Usertype_UID,
										);
									
									
									
									//$public_content += $User_Access_Level;
									//fail(-1, 'Unknown Error');
									
									/*
										============================================================
										SuperUser & Admin stuff --->
										------------------------------------------------------------
									*/
									if($User_Access_Level <= 1);
											/*
												============================================================
												"spoofUserTypeUID"
												------------------------------------------------------------
												Sets the `spoofUserTypeUID` variable that tracks the
												UserTypes.uid that is being spoofed.
												------------------------------------------------------------
											*/
											Define: -Name='spoof_User_Usertype_UID', -Default=$apparent_User_Usertype_UID;
											/*
												============================================================
												Spoof UserType information
												------------------------------------------------------------
												Grabs and sets the access level for the User
												------------------------------------------------------------
											*/
											inline(
												$connection_db,
												-Search,
												-Table='Usertypes',
												-Operator='eq', 'UID'=$spoof_User_Usertype_UID,
												-MaxRecords=1
												);
													if(found_count == 1);
															rows;
																	var(
																		'spoof_User_Access_Level' = integer(column('Access_Level')),
																		'spoof_User_Usertype_Title'= column('Title'),
																		);
															/rows;
															/*
																============================================================
																Apparent Authetication information
																------------------------------------------------------------
																Here is the variables that the authentication system reads.
																
																This is the information that the spoofing system presents to
																the page protection routines.
																------------------------------------------------------------
															*/
															var(
																'apparent_User_Usertype_UID' = $spoof_User_Usertype_UID,
																'apparent_User_Access_Level' = $spoof_User_Access_Level,
																'apparent_AuthenticationStatus' = $spoof_AuthenticationStatus,
																'apparent_User_Usertype_Title' = $spoof_User_Usertype_Title,
																);
													/if;
											/inline;
									/If;
									/*
										------------------------------------------------------------
										End - SuperUser & Admin
										============================================================
									*/
									
									
									
									
									/*
										============================================================
										Add 1 to number of logins
										------------------------------------------------------------
									*/
									var('User_Number_of_Logins_New' = $User_Number_of_Logins_Old + 1);
									
									
									/*
										============================================================
										Update login information
										------------------------------------------------------------
									*/
									inline(
										$connection_db,
										-Update,
										-Table='Users',
										-KeyField='UID',
										-KeyValue=$User_UID,
										'Number_of_Logins'=$User_Number_of_Logins_New,
										'Last_Logged_In'=(Date_Format: (Date), -Format='%Q %T'),
										);
									/inline;
									var('loginTries' = 0);
									
									
									/*
										============================================================
										Redirect to success page -- User is now signed in
										------------------------------------------------------------
									*/
									redirect_URL($base_path'#signedin');
									//$public_content += 'signed in1';
							else;
									/*
										============================================================
										Password did not match...
										------------------------------------------------------------
									*/
									
									
									
									
									Session_AddVariable: -Name='_SignInError', 'goTo';
									Session_AddVariable: -Name='_SignInError', 'loginTries';
									Session_AddVariable: -Name='_SignInError', 'signInErrorIs';
									
			

									
									
									/*
										============================================================
										bump Login tries by one
										------------------------------------------------------------
									*/
									If: (Variable_Defined:'loginTries') == true;
											$loginTries += 1;
									Else;
											Var: 'loginTries' = 1;
									/If;
									
									
									
									
									/*
										============================================================
										Sign in Error - password wrong
										------------------------------------------------------------
									*/
									Var: 'signInErrorIs' = 'Password incorrect';
									
									
									
									
									/*
										============================================================
										Redirect to error page
										------------------------------------------------------------
									*/
									//redirect_URL(string(response_path)->removetrailing('Account/Sign_In/Do/')'/Account/Sign_In/Error/');
									$public_content += error_msg;
							/If;
					/Inline;
			Else;
					/*
						============================================================
						Email NOT found
						------------------------------------------------------------
					*/
					Session_AddVariable: -Name='_SignInError', 'goTo';
					Session_AddVariable: -Name='_SignInError', 'loginTries';
					Session_AddVariable: -Name='_SignInError', 'signInErrorIs';
					
					
					
					
					/*
						============================================================
						Bump login tries by 1
						------------------------------------------------------------
					*/
					If: (Variable_Defined:'loginTries') == true;
							Var: 'loginTries' = $loginTries + 1;
					Else;
							Var: 'loginTries' = 1;
					/If;
					Var: 'signInErrorIs' = 'No account found';
					
					
					
					
					
					/*
						============================================================
						Redirect to error page
						------------------------------------------------------------
					*/
					redirect_URL($base_path 'Account/Sign_In/Error/');
					//$public_content += $signInErrorIs;
			/if;
	/Inline;

	handle_error;
			$public_content += error_msg;
	/handle_error;

	/protect;
//KTHNX
]